package com.tjetc.controller;
import com.github.pagehelper.PageInfo;
import com.tjetc.domain.Notice;
import com.tjetc.service.NoticeService;
import com.tjetc.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* (notice)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/notice")
public class NoticeController {
/**
* 服务对象
*/
@Resource
private NoticeService noticeService;

/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping("selectOne")
public Notice selectOne(Integer id) {
    return noticeService.selectByPrimaryKey(id);
}

@RequestMapping("findAllNotice")
public List<Notice> findAllNotice(){
    return noticeService.findAllNotice();
}

    @RequestMapping("getById")
    public Result getById(
            @RequestParam("id") Integer id
    ){
        return noticeService.getById(id);
    }

    @RequestMapping("list")
    public PageInfo<Notice> list(
            @RequestParam("title") String title,
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize
    ) {
        return noticeService.findByPage(title, pageNum, pageSize);
    }

    @RequestMapping("add")
    public Result add(@RequestBody Notice notice) {
        System.out.println(notice);
        return noticeService.addNotice(notice);
    }

    @RequestMapping("delete")
    public Result delete(@RequestParam("id") Integer id) {
        return noticeService.deleteNotice(id);
    }
}
